<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>Template Basics</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="web/style.css" rel="stylesheet" type="text/css" media="screen">
    <script type="text/javascript" src="web/js/jquery-1.7.1.js"></script>
    <script type="text/javascript">
		$(document).ready(function() {
			$("#productForm").hide();
			$("#accountForm").hide()
		});

		function addNewProductForm() {
			$("#Name").val("");
			$("#Price").val("");
			$("#Quantity").val("");
			$("#Category").val("");
			$("#Description").val("");
			$("#productForm").show('slow');
		}

		function selectProduct(ProductID) {
			$.getJSON('admin.php', {
			view : "product",
			do : "select",
			ProductID : ProductID
			}, function(data) {
				$("#ProductID").val(ProductID);
				$("#Name").val(data.Name);
				$("#Price").val(data.Price);
				$("#Quantity").val(data.Quantity);
				$("#Category").val(data.Category);
				$("#Description").val(data.Description);

			});
			$("#productForm").show('slow');
		}

		function deleteProduct(ProductID) {
			if (confirm('Are you sure want to delete product ' + ProductID + '?')) {
				$.ajax({
				type : "POST",
				url : "admin.php?view=product",
				data: { do: "delete", ProductID: ProductID }, success : function(data) {
					if (data > 0) {
						$("#" + ProductID).hide();
					}
				}
			});
			}
			else
			alert('Undeleted')
		}

		function addtocart(ProductID, sQuantity) {
			var Quantity = $('#' + ProductID).val();
			if (Quantity > sQuantity) {
				alert("order quantity is greater than the amount that");
				return;
			}
			$.ajax({
			type : "POST",
			url : "cart.php",
			data: { do: "add", ProductID: ProductID,Quantity:Quantity }, success : function(html) {
				$('#user-cart').html(html);
			}
		});

		}

		function removefromcart(ProductID) {
			$.ajax({
			type : "POST",
			url : "cart.php",
			data: { do: "remove", ProductID: ProductID }, success : function(html) {
				$('#user-cart').html(html);
				$('#' + ProductID).hide("slow");
			}
		});

		}

		function checkAccount() {

			var Account = $("#Account").val();
			$.ajax({
				type : "POST",
				url : "account.php?do=checkAccount",
				data : {
					Account : Account
				},
				success : function(html) {

					if (html == "true") {
						$('#checkaccount').html("<font color=red>This Account exist !</font>");
						$('#btnSubmit').attr("disabled", "disabled");
					} else {
						$('#checkaccount').html("<font color=blue>This Account Available!</font>");
						$('#btnSubmit').removeAttr("disabled");
					}
				}
			});
		}

		function addNewAccountForm() {
			$("#Account").val("");
			$("#Password").val("");
			$("#Name").val("");
			$("#Email").val("");
			$("#Birthday").val("");
			//$("#Role").val("");
			$("#Address").val("");
			$("#Phone").val("");
			$("#About").val("");
			$("#accountForm").show('slow');
		}

		function selectAccount(Account) {
			$.getJSON('admin.php', {
			view : "account",
			do : "select",
			Account : Account,
			}, function(data) {
				$("#Account").val(data.Account);
				$("#Password").val(data.Password);
				$("#Name").val(data.Name);
				$("#Email").val(data.Email);
				$("#Birthday").val(data.Birthday);
				$("#Role").val(data.Role);
				$("#Address").val(data.Address);
				$("#Phone").val(data.Phone);
				$("#About").val(data.About);

			});
			$("#accountForm").show('slow');
		}

		function deleteAccount(Account) {
			if (confirm('Are you sure want to delete Account ' + Account + '?')) {
				$.ajax({
				type : "POST",
				url : "admin.php?view=Account",
				data: { do: "delete", Account: Account }, success : function(html) {
					alert(html);
				}
			});
			}
			else
			alert('Undeleted')
		}
    </script>
</head>